/**
 * Copyright (c) 2011 Nokia Corporation.
 */

#ifndef DRIVEMODEL_H
#define DRIVEMODEL_H

// Qt includes
#include <QAbstractListModel>
#include <QList>

// Constants
const int BTGUndefined(-1);


/*!
  \class DriveInfo
  \brief Contains drive information.
*/
class DriveInfo
{
public:
    DriveInfo()
        : m_vol(QString()),
          m_type(BTGUndefined)
    { }

    ~DriveInfo() {}

    DriveInfo &operator=(const DriveInfo &info)
    {
        m_vol = info.m_vol;
        m_type = info.m_type;
        return *this;
    }

    bool operator==(const DriveInfo &info)
    {
        if (info.m_vol == m_vol && info.m_type == m_type) {
            return true;
        }

        return false;
    }

    bool operator!=(const DriveInfo &info)
    {
        if (info.m_vol != m_vol || info.m_type != m_type) {
            return true;
        }

        return false;
    }

public: // Data
    QString m_vol;
    int m_type;
};


class DriveModel : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)

public: // Data types

    enum DriveModelRoles {
        TypeRole = Qt::UserRole + 1,
        VolumeRole,
        NameRole
    };

public:
    explicit DriveModel(QObject *parent = 0);
    virtual ~DriveModel();

public: // From QAbstractListModel
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    void removeRow(int row, const QModelIndex &parent);

public:
    void appendDrive(DriveInfo &driveInfo);
    QString driveByIndex(int index) const;

public slots:
    void setFilters(QList<int> &filters);
    void filterRemovableDrivesOnly();
    void filterInternalDrivesOnly();
    void clear(bool allDrives = true);
    void refresh();

private:
    void appendFilteredDrive(DriveInfo &driveInfo);

signals:
    void rowCountChanged(int count);

private: // Data
    QList<DriveInfo> m_allDrives;
    QList<DriveInfo> m_filteredDrives;
    QList<int> m_filters;
};


#endif // DRIVEMODEL_H

// End of file.
